package com.tjsinfo.tjsoa.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.system.bo.ISystemUserRoleBO;
import com.tjsinfo.tjsoa.system.bo.ITjsRolesBo;
import com.tjsinfo.tjsoa.system.vo.TjsRoles;

/**
 * 查询用户所有的权限
 * @author Administrator
 *
 */
public class SelectupdateAllRoles extends Action{
	private ITjsRolesBo tjsRolesBo;
	private ISystemUserRoleBO systemUserRoleBO;
	
	public ISystemUserRoleBO getSystemUserRoleBO() {
		return systemUserRoleBO;
	}

	public void setSystemUserRoleBO(ISystemUserRoleBO systemUserRoleBO) {
		this.systemUserRoleBO = systemUserRoleBO;
	}

	public ITjsRolesBo getTjsRolesBo() {
		return tjsRolesBo;
	}

	public void setTjsRolesBo(ITjsRolesBo tjsRolesBo) {
		this.tjsRolesBo = tjsRolesBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Integer id =  Integer.parseInt(request.getParameter("id"));
		List<TjsRoles> list = tjsRolesBo.selectAllRloes();
		JSONArray array = new JSONArray();
		for (TjsRoles tjsRoles : list) {
			JSONObject object = new JSONObject(tjsRoles);
			if (systemUserRoleBO.selectUserRoleByUserId(Integer.parseInt(tjsRoles.getRoleId().substring(1,tjsRoles.getRoleId().length()-1)) , id)) {
				object.put("chk", true);
			} else {
				object.put("chk", false);	
			}
			object.put("id", tjsRoles.getRoleId().substring(1,tjsRoles.getRoleId().length() - 1));
			array.put(object);
		}
		response.getWriter().print(array);
		
		
		return null;
	}
	
}
